package com.wms.initLink;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.wms.crypt.BrowserEncryption;
import com.wms.crypt.ServerEncryption;
import com.wms.interfc.InterfaceDoRun;
import com.wms.uitl.ConvertMap2Json;

/*
 * 初始化连接，当view首次链接server时，将加密用到的公/私钥传递给view
 */


@Service
public class InitLink implements InterfaceDoRun{
	
	@Resource
	private ServerEncryption sCrypt;  //server 端的密钥对象
	
	@Resource
	private BrowserEncryption bCrypt; //browser 端的密钥对象
	
	@Resource
	private ConvertMap2Json convertor; //工具类，将map装换成json string，并对json string  url 加密
	
	public String doRun(String content)throws Exception{
		
		Map<String,String>  response = new HashMap<String, String>();
		
		response.put("generatorUN",bCrypt.getKeyN());
		response.put("generatorUE",bCrypt.getKeyE());  //browser 端的公钥
		
		response.put("generatorRN",sCrypt.getKeyN());
		response.put("generatorRE",sCrypt.getKeyE());
		response.put("generatorRD",sCrypt.getKeyD());  //server端的私钥
		
		return convertor.convertWithoutEncrypt(response); // 格式转换
	}
}
